/*
===============================================================================
                    EntitySpaces 2009 by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2009.2.1214.0
EntitySpaces Driver  : SQL
Date Generated       : 1/26/2010 10:20:34 AM
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;


using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;


using DotNetNuke.Framework.Providers;


namespace DNNspot.LiveChat.DataModel
{

	[Serializable]
	abstract public class esUserCollection : esEntityCollection
	{
		public esUserCollection()
		{

		}

		protected override string GetCollectionName()
		{
			return "UserCollection";
		}

		#region Query Logic
		protected void InitQuery(esUserQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			query.es2.Connection = ((IEntityCollection)this).Connection;
		}

		protected bool OnQueryLoaded(DataTable table)
		{
			this.PopulateCollection(table);
			return (this.RowCount > 0) ? true : false;
		}
		
		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery(query as esUserQuery);
		}
		#endregion
		
		virtual public User DetachEntity(User entity)
		{
			return base.DetachEntity(entity) as User;
		}
		
		virtual public User AttachEntity(User entity)
		{
			return base.AttachEntity(entity) as User;
		}
		
		virtual public void Combine(UserCollection collection)
		{
			base.Combine(collection);
		}
		
		new public User this[int index]
		{
			get
			{
				return base[index] as User;
			}
		}

		public override Type GetEntityType()
		{
			return typeof(User);
		}
	}



	[Serializable]
	abstract public class esUser : esEntity
	{
		/// <summary>
		/// Used internally by the entity's DynamicQuery mechanism.
		/// </summary>
		virtual protected esUserQuery GetDynamicQuery()
		{
			return null;
		}

		public esUser()
		{

		}

		public esUser(DataRow row)
			: base(row)
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Int32 userID)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(userID);
			else
				return LoadByPrimaryKeyStoredProcedure(userID);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Int32 userID)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(userID);
			else
				return LoadByPrimaryKeyStoredProcedure(userID);
		}

		private bool LoadByPrimaryKeyDynamic(System.Int32 userID)
		{
			esUserQuery query = this.GetDynamicQuery();
			query.Where(query.UserID == userID);
			return query.Load();
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Int32 userID)
		{
			esParameters parms = new esParameters();
			parms.Add("UserID",userID);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		
		
		#region Properties
		
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}

		public override void SetProperty(string name, object value)
		{
			if(this.Row == null) this.AddNew();
			
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "UserID": this.str.UserID = (string)value; break;							
						case "Username": this.str.Username = (string)value; break;							
						case "FirstName": this.str.FirstName = (string)value; break;							
						case "LastName": this.str.LastName = (string)value; break;							
						case "IsSuperUser": this.str.IsSuperUser = (string)value; break;							
						case "AffiliateId": this.str.AffiliateId = (string)value; break;							
						case "Email": this.str.Email = (string)value; break;							
						case "DisplayName": this.str.DisplayName = (string)value; break;							
						case "UpdatePassword": this.str.UpdatePassword = (string)value; break;							
						case "LastIPAddress": this.str.LastIPAddress = (string)value; break;							
						case "IsDeleted": this.str.IsDeleted = (string)value; break;							
						case "CreatedByUserID": this.str.CreatedByUserID = (string)value; break;							
						case "CreatedOnDate": this.str.CreatedOnDate = (string)value; break;							
						case "LastModifiedByUserID": this.str.LastModifiedByUserID = (string)value; break;							
						case "LastModifiedOnDate": this.str.LastModifiedOnDate = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "UserID":
						
							if (value == null || value is System.Int32)
								this.UserID = (System.Int32?)value;
							break;
						
						case "IsSuperUser":
						
							if (value == null || value is System.Boolean)
								this.IsSuperUser = (System.Boolean?)value;
							break;
						
						case "AffiliateId":
						
							if (value == null || value is System.Int32)
								this.AffiliateId = (System.Int32?)value;
							break;
						
						case "UpdatePassword":
						
							if (value == null || value is System.Boolean)
								this.UpdatePassword = (System.Boolean?)value;
							break;
						
						case "IsDeleted":
						
							if (value == null || value is System.Boolean)
								this.IsDeleted = (System.Boolean?)value;
							break;
						
						case "CreatedByUserID":
						
							if (value == null || value is System.Int32)
								this.CreatedByUserID = (System.Int32?)value;
							break;
						
						case "CreatedOnDate":
						
							if (value == null || value is System.DateTime)
								this.CreatedOnDate = (System.DateTime?)value;
							break;
						
						case "LastModifiedByUserID":
						
							if (value == null || value is System.Int32)
								this.LastModifiedByUserID = (System.Int32?)value;
							break;
						
						case "LastModifiedOnDate":
						
							if (value == null || value is System.DateTime)
								this.LastModifiedOnDate = (System.DateTime?)value;
							break;
					

						default:
							break;
					}
				}
			}
			else if(this.Row.Table.Columns.Contains(name))
			{
				this.Row[name] = value;
			}
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}
		
		
		/// <summary>
		/// Maps to Users.UserID
		/// </summary>
		virtual public System.Int32? UserID
		{
			get
			{
				return base.GetSystemInt32(UserMetadata.ColumnNames.UserID);
			}
			
			set
			{
				base.SetSystemInt32(UserMetadata.ColumnNames.UserID, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.Username
		/// </summary>
		virtual public System.String Username
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.Username);
			}
			
			set
			{
				base.SetSystemString(UserMetadata.ColumnNames.Username, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.FirstName
		/// </summary>
		virtual public System.String FirstName
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.FirstName);
			}
			
			set
			{
				base.SetSystemString(UserMetadata.ColumnNames.FirstName, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.LastName
		/// </summary>
		virtual public System.String LastName
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.LastName);
			}
			
			set
			{
				base.SetSystemString(UserMetadata.ColumnNames.LastName, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.IsSuperUser
		/// </summary>
		virtual public System.Boolean? IsSuperUser
		{
			get
			{
				return base.GetSystemBoolean(UserMetadata.ColumnNames.IsSuperUser);
			}
			
			set
			{
				base.SetSystemBoolean(UserMetadata.ColumnNames.IsSuperUser, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.AffiliateId
		/// </summary>
		virtual public System.Int32? AffiliateId
		{
			get
			{
				return base.GetSystemInt32(UserMetadata.ColumnNames.AffiliateId);
			}
			
			set
			{
				base.SetSystemInt32(UserMetadata.ColumnNames.AffiliateId, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.Email
		/// </summary>
		virtual public System.String Email
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.Email);
			}
			
			set
			{
				base.SetSystemString(UserMetadata.ColumnNames.Email, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.DisplayName
		/// </summary>
		virtual public System.String DisplayName
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.DisplayName);
			}
			
			set
			{
				base.SetSystemString(UserMetadata.ColumnNames.DisplayName, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.UpdatePassword
		/// </summary>
		virtual public System.Boolean? UpdatePassword
		{
			get
			{
				return base.GetSystemBoolean(UserMetadata.ColumnNames.UpdatePassword);
			}
			
			set
			{
				base.SetSystemBoolean(UserMetadata.ColumnNames.UpdatePassword, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.LastIPAddress
		/// </summary>
		virtual public System.String LastIPAddress
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.LastIPAddress);
			}
			
			set
			{
				base.SetSystemString(UserMetadata.ColumnNames.LastIPAddress, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.IsDeleted
		/// </summary>
		virtual public System.Boolean? IsDeleted
		{
			get
			{
				return base.GetSystemBoolean(UserMetadata.ColumnNames.IsDeleted);
			}
			
			set
			{
				base.SetSystemBoolean(UserMetadata.ColumnNames.IsDeleted, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.CreatedByUserID
		/// </summary>
		virtual public System.Int32? CreatedByUserID
		{
			get
			{
				return base.GetSystemInt32(UserMetadata.ColumnNames.CreatedByUserID);
			}
			
			set
			{
				base.SetSystemInt32(UserMetadata.ColumnNames.CreatedByUserID, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.CreatedOnDate
		/// </summary>
		virtual public System.DateTime? CreatedOnDate
		{
			get
			{
				return base.GetSystemDateTime(UserMetadata.ColumnNames.CreatedOnDate);
			}
			
			set
			{
				base.SetSystemDateTime(UserMetadata.ColumnNames.CreatedOnDate, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.LastModifiedByUserID
		/// </summary>
		virtual public System.Int32? LastModifiedByUserID
		{
			get
			{
				return base.GetSystemInt32(UserMetadata.ColumnNames.LastModifiedByUserID);
			}
			
			set
			{
				base.SetSystemInt32(UserMetadata.ColumnNames.LastModifiedByUserID, value);
			}
		}
		
		/// <summary>
		/// Maps to Users.LastModifiedOnDate
		/// </summary>
		virtual public System.DateTime? LastModifiedOnDate
		{
			get
			{
				return base.GetSystemDateTime(UserMetadata.ColumnNames.LastModifiedOnDate);
			}
			
			set
			{
				base.SetSystemDateTime(UserMetadata.ColumnNames.LastModifiedOnDate, value);
			}
		}
		
		#endregion	

		#region String Properties


		[BrowsableAttribute( false )]
		public esStrings str
		{
			get
			{
				if (esstrings == null)
				{
					esstrings = new esStrings(this);
				}
				return esstrings;
			}
		}


		[Serializable]
		sealed public class esStrings
		{
			public esStrings(esUser entity)
			{
				this.entity = entity;
			}
			
	
			public System.String UserID
			{
				get
				{
					System.Int32? data = entity.UserID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.UserID = null;
					else entity.UserID = Convert.ToInt32(value);
				}
			}
				
			public System.String Username
			{
				get
				{
					System.String data = entity.Username;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Username = null;
					else entity.Username = Convert.ToString(value);
				}
			}
				
			public System.String FirstName
			{
				get
				{
					System.String data = entity.FirstName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FirstName = null;
					else entity.FirstName = Convert.ToString(value);
				}
			}
				
			public System.String LastName
			{
				get
				{
					System.String data = entity.LastName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastName = null;
					else entity.LastName = Convert.ToString(value);
				}
			}
				
			public System.String IsSuperUser
			{
				get
				{
					System.Boolean? data = entity.IsSuperUser;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.IsSuperUser = null;
					else entity.IsSuperUser = Convert.ToBoolean(value);
				}
			}
				
			public System.String AffiliateId
			{
				get
				{
					System.Int32? data = entity.AffiliateId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.AffiliateId = null;
					else entity.AffiliateId = Convert.ToInt32(value);
				}
			}
				
			public System.String Email
			{
				get
				{
					System.String data = entity.Email;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Email = null;
					else entity.Email = Convert.ToString(value);
				}
			}
				
			public System.String DisplayName
			{
				get
				{
					System.String data = entity.DisplayName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.DisplayName = null;
					else entity.DisplayName = Convert.ToString(value);
				}
			}
				
			public System.String UpdatePassword
			{
				get
				{
					System.Boolean? data = entity.UpdatePassword;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.UpdatePassword = null;
					else entity.UpdatePassword = Convert.ToBoolean(value);
				}
			}
				
			public System.String LastIPAddress
			{
				get
				{
					System.String data = entity.LastIPAddress;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastIPAddress = null;
					else entity.LastIPAddress = Convert.ToString(value);
				}
			}
				
			public System.String IsDeleted
			{
				get
				{
					System.Boolean? data = entity.IsDeleted;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.IsDeleted = null;
					else entity.IsDeleted = Convert.ToBoolean(value);
				}
			}
				
			public System.String CreatedByUserID
			{
				get
				{
					System.Int32? data = entity.CreatedByUserID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedByUserID = null;
					else entity.CreatedByUserID = Convert.ToInt32(value);
				}
			}
				
			public System.String CreatedOnDate
			{
				get
				{
					System.DateTime? data = entity.CreatedOnDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedOnDate = null;
					else entity.CreatedOnDate = Convert.ToDateTime(value);
				}
			}
				
			public System.String LastModifiedByUserID
			{
				get
				{
					System.Int32? data = entity.LastModifiedByUserID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastModifiedByUserID = null;
					else entity.LastModifiedByUserID = Convert.ToInt32(value);
				}
			}
				
			public System.String LastModifiedOnDate
			{
				get
				{
					System.DateTime? data = entity.LastModifiedOnDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastModifiedOnDate = null;
					else entity.LastModifiedOnDate = Convert.ToDateTime(value);
				}
			}
			

			private esUser entity;
		}
		#endregion

		#region Query Logic
		protected void InitQuery(esUserQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			query.es2.Connection = ((IEntity)this).Connection;
		}

		[System.Diagnostics.DebuggerNonUserCode]
		protected bool OnQueryLoaded(DataTable table)
		{
			bool dataFound = this.PopulateEntity(table);

			if (this.RowCount > 1)
			{
				throw new Exception("esUser can only hold one record of data");
			}

			return dataFound;
		}
		#endregion
		
		[NonSerialized]
		private esStrings esstrings;
	}


	
	public partial class User : esUser
	{

				
		#region AgentCollectionByUserId - Zero To Many
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_DNNspot_LiveChat_Agents_Users
		/// </summary>

		[XmlIgnore]
		public AgentCollection AgentCollectionByUserId
		{
			get
			{
				if(this._AgentCollectionByUserId == null)
				{
					this._AgentCollectionByUserId = new AgentCollection();
					this._AgentCollectionByUserId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("AgentCollectionByUserId", this._AgentCollectionByUserId);
				
					if(this.UserID != null)
					{
						this._AgentCollectionByUserId.Query.Where(this._AgentCollectionByUserId.Query.UserId == this.UserID);
						this._AgentCollectionByUserId.Query.Load();

						// Auto-hookup Foreign Keys
						this._AgentCollectionByUserId.fks.Add(AgentMetadata.ColumnNames.UserId, this.UserID);
					}
				}

				return this._AgentCollectionByUserId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._AgentCollectionByUserId != null) 
				{ 
					this.RemovePostSave("AgentCollectionByUserId"); 
					this._AgentCollectionByUserId = null;
					
				} 
			} 			
		}

		private AgentCollection _AgentCollectionByUserId;
		#endregion

				
		#region ClientCollectionByUserId - Zero To Many
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_DNNspot_LiveChat_Clients_Users
		/// </summary>

		[XmlIgnore]
		public ClientCollection ClientCollectionByUserId
		{
			get
			{
				if(this._ClientCollectionByUserId == null)
				{
					this._ClientCollectionByUserId = new ClientCollection();
					this._ClientCollectionByUserId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("ClientCollectionByUserId", this._ClientCollectionByUserId);
				
					if(this.UserID != null)
					{
						this._ClientCollectionByUserId.Query.Where(this._ClientCollectionByUserId.Query.UserId == this.UserID);
						this._ClientCollectionByUserId.Query.Load();

						// Auto-hookup Foreign Keys
						this._ClientCollectionByUserId.fks.Add(ClientMetadata.ColumnNames.UserId, this.UserID);
					}
				}

				return this._ClientCollectionByUserId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._ClientCollectionByUserId != null) 
				{ 
					this.RemovePostSave("ClientCollectionByUserId"); 
					this._ClientCollectionByUserId = null;
					
				} 
			} 			
		}

		private ClientCollection _ClientCollectionByUserId;
		#endregion

		
		/// <summary>
		/// Used internally by the entity's hierarchical properties.
		/// </summary>
		protected override List<esPropertyDescriptor> GetHierarchicalProperties()
		{
			List<esPropertyDescriptor> props = new List<esPropertyDescriptor>();
			
			props.Add(new esPropertyDescriptor(this, "AgentCollectionByUserId", typeof(AgentCollection), new Agent()));
			props.Add(new esPropertyDescriptor(this, "ClientCollectionByUserId", typeof(ClientCollection), new Client()));
		
			return props;
		}	
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PreSave.
		/// </summary>
		protected override void ApplyPreSaveKeys()
		{
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostSave.
		/// </summary>
		protected override void ApplyPostSaveKeys()
		{
			if(this._AgentCollectionByUserId != null)
			{
				foreach(Agent obj in this._AgentCollectionByUserId)
				{
					if(obj.es.IsAdded)
					{
						obj.UserId = this.UserID;
					}
				}
			}
			if(this._ClientCollectionByUserId != null)
			{
				foreach(Client obj in this._ClientCollectionByUserId)
				{
					if(obj.es.IsAdded)
					{
						obj.UserId = this.UserID;
					}
				}
			}
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostOneToOneSave.
		/// </summary>
		protected override void ApplyPostOneSaveKeys()
		{
		}
		
	}



	[Serializable]
	abstract public class esUserQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return UserMetadata.Meta();
			}
		}	
		

		public esQueryItem UserID
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.UserID, esSystemType.Int32);
			}
		} 
		
		public esQueryItem Username
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.Username, esSystemType.String);
			}
		} 
		
		public esQueryItem FirstName
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.FirstName, esSystemType.String);
			}
		} 
		
		public esQueryItem LastName
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.LastName, esSystemType.String);
			}
		} 
		
		public esQueryItem IsSuperUser
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.IsSuperUser, esSystemType.Boolean);
			}
		} 
		
		public esQueryItem AffiliateId
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.AffiliateId, esSystemType.Int32);
			}
		} 
		
		public esQueryItem Email
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.Email, esSystemType.String);
			}
		} 
		
		public esQueryItem DisplayName
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.DisplayName, esSystemType.String);
			}
		} 
		
		public esQueryItem UpdatePassword
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.UpdatePassword, esSystemType.Boolean);
			}
		} 
		
		public esQueryItem LastIPAddress
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.LastIPAddress, esSystemType.String);
			}
		} 
		
		public esQueryItem IsDeleted
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.IsDeleted, esSystemType.Boolean);
			}
		} 
		
		public esQueryItem CreatedByUserID
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.CreatedByUserID, esSystemType.Int32);
			}
		} 
		
		public esQueryItem CreatedOnDate
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.CreatedOnDate, esSystemType.DateTime);
			}
		} 
		
		public esQueryItem LastModifiedByUserID
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.LastModifiedByUserID, esSystemType.Int32);
			}
		} 
		
		public esQueryItem LastModifiedOnDate
		{
			get
			{
				return new esQueryItem(this, UserMetadata.ColumnNames.LastModifiedOnDate, esSystemType.DateTime);
			}
		} 
		
	}



    [System.Diagnostics.DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[XmlType("UserCollection")]
	public partial class UserCollection : esUserCollection, IEnumerable<User>
	{
		public UserCollection()
		{

		}
		
		public static implicit operator List<User>(UserCollection coll)
		{
			List<User> list = new List<User>();
			
			foreach (User emp in coll)
			{
				list.Add(emp);
			}
			
			return list;
		}
		
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return  UserMetadata.Meta();
			}
		}
		
		
		
		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new UserQuery();
				this.InitQuery(query);
			}
			return this.query;
		}
		
		override protected esEntity CreateEntityForCollection(DataRow row)
		{
			return new User(row);
		}

		override protected esEntity CreateEntity()
		{
			return new User();
		}
		
		
		#endregion


		[BrowsableAttribute( false )]
		public UserQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new UserQuery();
					base.InitQuery(this.query);
				}

				return this.query;
			}
		}

		public void QueryReset()
		{
			this.query = null;
		}

		public bool Load(UserQuery query)
		{
			this.query = query;
			base.InitQuery(this.query);
			return this.Query.Load();
		}
		
		public User AddNew()
		{
			User entity = base.AddNewEntity() as User;
			
			return entity;
		}

		public User FindByPrimaryKey(System.Int32 userID)
		{
			return base.FindByPrimaryKey(userID) as User;
		}


		#region IEnumerable<User> Members

		IEnumerator<User> IEnumerable<User>.GetEnumerator()
		{
			System.Collections.IEnumerable enumer = this as System.Collections.IEnumerable;
			System.Collections.IEnumerator iterator = enumer.GetEnumerator();

			while(iterator.MoveNext())
			{
				yield return iterator.Current as User;
			}
		}

		#endregion
		
		private UserQuery query;
	}


	/// <summary>
	/// Encapsulates the 'Users' table
	/// </summary>

    [System.Diagnostics.DebuggerDisplay("User ({UserID})")]
	[Serializable]
	public partial class User : esUser
	{
		public User()
		{

		}
	
		public User(DataRow row)
			: base(row)
		{

		}
		
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return UserMetadata.Meta();
			}
		}
		
		
		
		override protected esUserQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new UserQuery();
				this.InitQuery(query);
			}
			return this.query;
		}
		#endregion
		



		[BrowsableAttribute( false )]
		public UserQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new UserQuery();
					base.InitQuery(this.query);
				}

				return this.query;
			}
		}

		public void QueryReset()
		{
			this.query = null;
		}
		

		public bool Load(UserQuery query)
		{
			this.query = query;
			base.InitQuery(this.query);
			return this.Query.Load();
		}
		
		private UserQuery query;
	}



    [System.Diagnostics.DebuggerDisplay("LastQuery = {es.LastQuery}")]
	[Serializable]
		
	public partial class UserQuery : esUserQuery
	{
		public UserQuery()
		{

		}		
		
		public UserQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

        override protected string GetQueryName()
        {
            return "UserQuery";
        }
		
			
	}


	[Serializable]
	public partial class UserMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected UserMetadata()
		{
			_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(UserMetadata.ColumnNames.UserID, 0, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = UserMetadata.PropertyNames.UserID;
			c.IsInPrimaryKey = true;
			c.IsAutoIncrement = true;
			c.NumericPrecision = 10;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.Username, 1, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.Username;
			c.CharacterMaxLength = 100;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.FirstName, 2, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.FirstName;
			c.CharacterMaxLength = 50;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.LastName, 3, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.LastName;
			c.CharacterMaxLength = 50;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.IsSuperUser, 4, typeof(System.Boolean), esSystemType.Boolean);
			c.PropertyName = UserMetadata.PropertyNames.IsSuperUser;
			c.HasDefault = true;
			c.Default = @"((0))";
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.AffiliateId, 5, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = UserMetadata.PropertyNames.AffiliateId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.Email, 6, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.Email;
			c.CharacterMaxLength = 256;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.DisplayName, 7, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.DisplayName;
			c.CharacterMaxLength = 128;
			c.HasDefault = true;
			c.Default = @"('')";
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.UpdatePassword, 8, typeof(System.Boolean), esSystemType.Boolean);
			c.PropertyName = UserMetadata.PropertyNames.UpdatePassword;
			c.HasDefault = true;
			c.Default = @"((0))";
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.LastIPAddress, 9, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.LastIPAddress;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.IsDeleted, 10, typeof(System.Boolean), esSystemType.Boolean);
			c.PropertyName = UserMetadata.PropertyNames.IsDeleted;
			c.HasDefault = true;
			c.Default = @"((0))";
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.CreatedByUserID, 11, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = UserMetadata.PropertyNames.CreatedByUserID;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.CreatedOnDate, 12, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = UserMetadata.PropertyNames.CreatedOnDate;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.LastModifiedByUserID, 13, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = UserMetadata.PropertyNames.LastModifiedByUserID;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.LastModifiedOnDate, 14, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = UserMetadata.PropertyNames.LastModifiedOnDate;
			c.IsNullable = true;
			_columns.Add(c);
				
		}
		#endregion	
	
		static public UserMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base._dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base._columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string UserID = "UserID";
			 public const string Username = "Username";
			 public const string FirstName = "FirstName";
			 public const string LastName = "LastName";
			 public const string IsSuperUser = "IsSuperUser";
			 public const string AffiliateId = "AffiliateId";
			 public const string Email = "Email";
			 public const string DisplayName = "DisplayName";
			 public const string UpdatePassword = "UpdatePassword";
			 public const string LastIPAddress = "LastIPAddress";
			 public const string IsDeleted = "IsDeleted";
			 public const string CreatedByUserID = "CreatedByUserID";
			 public const string CreatedOnDate = "CreatedOnDate";
			 public const string LastModifiedByUserID = "LastModifiedByUserID";
			 public const string LastModifiedOnDate = "LastModifiedOnDate";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string UserID = "UserID";
			 public const string Username = "Username";
			 public const string FirstName = "FirstName";
			 public const string LastName = "LastName";
			 public const string IsSuperUser = "IsSuperUser";
			 public const string AffiliateId = "AffiliateId";
			 public const string Email = "Email";
			 public const string DisplayName = "DisplayName";
			 public const string UpdatePassword = "UpdatePassword";
			 public const string LastIPAddress = "LastIPAddress";
			 public const string IsDeleted = "IsDeleted";
			 public const string CreatedByUserID = "CreatedByUserID";
			 public const string CreatedOnDate = "CreatedOnDate";
			 public const string LastModifiedByUserID = "LastModifiedByUserID";
			 public const string LastModifiedOnDate = "LastModifiedOnDate";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(UserMetadata))
			{
				if(UserMetadata.mapDelegates == null)
				{
					UserMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (UserMetadata.meta == null)
				{
					UserMetadata.meta = new UserMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();
				

				meta.AddTypeMap("UserID", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("Username", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("FirstName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("LastName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("IsSuperUser", new esTypeMap("bit", "System.Boolean"));
				meta.AddTypeMap("AffiliateId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("Email", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("DisplayName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("UpdatePassword", new esTypeMap("bit", "System.Boolean"));
				meta.AddTypeMap("LastIPAddress", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("IsDeleted", new esTypeMap("bit", "System.Boolean"));
				meta.AddTypeMap("CreatedByUserID", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("CreatedOnDate", new esTypeMap("datetime", "System.DateTime"));
				meta.AddTypeMap("LastModifiedByUserID", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("LastModifiedOnDate", new esTypeMap("datetime", "System.DateTime"));			
				
				
				
				ProviderConfiguration providerConfiguration = ProviderConfiguration.GetProviderConfiguration("data");
				Provider provider = (Provider)providerConfiguration.Providers[providerConfiguration.DefaultProvider];

				string objectQualifier = provider.Attributes["objectQualifier"];

				if ((objectQualifier != string.Empty) && (objectQualifier.EndsWith("_") == false))
				{
					objectQualifier += "_";
				}

				if (objectQualifier != string.Empty)
				{
					meta.Source = objectQualifier + "Users";
					meta.Destination = objectQualifier + "Users";
					
					meta.spInsert = objectQualifier + "proc_UsersInsert";				
					meta.spUpdate = objectQualifier + "proc_UsersUpdate";		
					meta.spDelete = objectQualifier + "proc_UsersDelete";
					meta.spLoadAll = objectQualifier + "proc_UsersLoadAll";
					meta.spLoadByPrimaryKey = objectQualifier + "proc_UsersLoadByPrimaryKey";
				}
				else
				{
					meta.Source = "Users";
					meta.Destination = "Users";
									
					meta.spInsert = "proc_UsersInsert";				
					meta.spUpdate = "proc_UsersUpdate";		
					meta.spDelete = "proc_UsersDelete";
					meta.spLoadAll = "proc_UsersLoadAll";
					meta.spLoadByPrimaryKey = "proc_UsersLoadByPrimaryKey";
				}
				
				
				this._providerMetadataMaps["esDefault"] = meta;
			}
			
			return this._providerMetadataMaps["esDefault"];
		}

		#endregion

		static private UserMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
